Support GitHub Enterprise deployments via environment-aware URLs#16309
Support GitHub Enterprise deployments via environment-aware URLs#16309
Conversation
…ise support Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
pkg/parser/remote_fetch.go
Outdated
|
|
||
| repoURL := fmt.Sprintf("https://github.com/%s/%s.git", owner, repo) | ||
| // Get GitHub host from environment with fallback | ||
| githubHost := os.Getenv("GITHUB_SERVER_URL") |
There was a problem hiding this comment.
Refactored to use a getGitHubHost() helper function in the parser package. All three instances of the duplicated code now use the helper. (d961583)
…e duplication Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds support for GitHub Enterprise deployments by replacing hardcoded https://github.com URLs with environment-aware URLs throughout the Go codebase. The implementation uses a getGitHubHost() helper function that checks GITHUB_SERVER_URL (GitHub Actions standard), then GH_HOST (gh CLI standard), and defaults to https://github.com.
Changes:
- Introduced
ValidateCopilotPATWithHost()function inpkg/stringutil/pat_validation.goto support enterprise-aware error messages - Added
getGitHubHost()helper inpkg/parser/remote_fetch.goto avoid circular dependencies - Updated 13 Go files across CLI and parser packages to use environment-aware GitHub URLs
- Added comprehensive test coverage for enterprise host URL validation
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/stringutil/pat_validation.go | Added ValidateCopilotPATWithHost() function to support enterprise GitHub URLs in PAT validation error messages; existing ValidateCopilotPAT() now delegates to this function with default host |
| pkg/stringutil/pat_validation_test.go | Added TestValidateCopilotPATWithHost with 6 test cases covering both default and enterprise hosts for all token types |
| pkg/parser/remote_fetch.go | Added package-local getGitHubHost() helper and updated 3 git operations (ls-remote, archive, clone) to use enterprise-aware URLs |
| pkg/cli/update_actions.go | Updated git ls-remote URL construction to use getGitHubHost() |
| pkg/cli/trial_repository.go | Updated 8 URLs including repository creation messages, Actions settings links, and git clone operations |
| pkg/cli/trial_command.go | Updated workflow run URLs and repository preservation messages |
| pkg/cli/secret_collection.go | Updated PAT creation URL in prompt message |
| pkg/cli/pr_command.go | Updated fork and upstream remote URLs for cross-repository PR creation |
| pkg/cli/download_workflow.go | Updated 6 git operations (ls-remote for tags, branches, default branch; git archive and clone) |
| pkg/cli/add_interactive_workflow.go | Updated GitHub Actions page URL for Codespaces users |
| pkg/cli/add_interactive_engine.go | Updated PAT creation URL in prompt message |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Added support for Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| } | ||
| if host == "" { | ||
| // Try to derive from GITHUB_API_URL | ||
| if apiURL := os.Getenv("GITHUB_API_URL"); apiURL != "" { |
| // then falls back to GH_HOST (gh CLI standard), | ||
| // then derives from GITHUB_API_URL if available, | ||
| // and finally defaults to https://github.com | ||
| func getGitHubHost() string { |
There was a problem hiding this comment.
@copilot delete this function and use getGithubhost in GitHub package
Enterprise GitHub URL Support
Replace all hardcoded "https://github.com" references with environment-aware URLs that support GitHub Enterprise deployments.
Summary of Changes
Go Files Updated (13 files):
pkg/cli/trial_repository.go- Repository creation, cloning URLs, and settings URLs (8 changes)pkg/cli/pr_command.go- Fork and remote URLs (2 changes)pkg/cli/secret_collection.go- PAT creation URL (1 change)pkg/cli/add_interactive_engine.go- PAT creation URL (1 change)pkg/cli/add_interactive_workflow.go- Actions page URL (1 change)pkg/cli/download_workflow.go- Git ls-remote and clone URLs (6 changes)pkg/cli/trial_command.go- Workflow run URLs and repo URLs (3 changes)pkg/cli/update_actions.go- Git ls-remote URL (1 change)pkg/parser/remote_fetch.go- Git fallback URLs (3 changes) + helper functionpkg/stringutil/pat_validation.go- AddedValidateCopilotPATWithHost()for enterprise-aware error messagespkg/cli/github.go- Enhanced helper to support GITHUB_API_URLpkg/parser/remote_fetch.go- Enhanced helper to support GITHUB_API_URLJavaScript/Shell Scripts:
.cjsfiles already correctly useprocess.env.GITHUB_SERVER_URL || "https://github.com"$GITHUB_SERVER_URLwith fallbackTests Added:
TestValidateCopilotPATWithHost- Validates enterprise host URLs in error messages (6 test cases)TestGetGitHubHost- Enhanced with GITHUB_API_URL test coverage (12 test cases)Implementation Details
Both
getGitHubHost()helpers now support multiple environment variables with automatic URL derivation:Environment variable priority order:
https://github.enterprise.com)github.enterprise.comorhttps://github.enterprise.com)https://prefix if only hostname is providedhttps://api.github.com→https://github.saobby.my.eu.orghttps://api.github.enterprise.com→https://github.enterprise.comhttps://github.enterprise.com/api/v3→https://github.enterprise.comhttps://github.saobby.my.eu.orgCLI package (
pkg/cli/github.go):Parser package (
pkg/parser/remote_fetch.go):URLs Updated
User-facing URLs:
Internal git operations:
git clone)git ls-remote)git archive)Plan
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.